#pragma once
#include <QApplication>
#include <QMainWindow>
#include <iostream>

#include "src/qbe.hpp"

using namespace qbe;
struct MyEvent {
  int message;
};

void event_trigger(ecs::EventWriter<MyEvent> event) {
  event.send(MyEvent{1});
}

// template <typename T>
void event_listener(ecs::EventReader<MyEvent> events, ecs::World& world) {
  auto it = events.read();
  for (auto my_event : events) {
    std::cerr << my_event.message << std::endl;
  }
}

void event_clear(ecs::Resource<ecs::Event<MyEvent>> res) {
  res.get().clear();
}

int main(int argc, char* argv[]) {
  QApplication application(argc, argv);

  ecs::App app;

  app.add_stage<ecs::stage::Startup>();
  app.add_stage<ecs::stage::Update>();
  app.add_stage<ecs::stage::Last>();

  // 插入事件资源
  app.insert_resource<ecs::Event<MyEvent>>(ecs::Event<MyEvent>{});
  // 发送事件消息
  app.add_systems<ecs::stage::Startup>(event_trigger);
  // 读取事件消息
  app.add_systems<ecs::stage::Update>(event_listener);
  // 清除事件消息
  app.add_systems<ecs::stage::Last>(event_clear);
  app.run();

  return application.exec();
}